<template>
    <view class="flex-layout-row">
       <!--<mui-button @action="makeCall" icon="icon-call" :text="showText ? 'Call' : ''" bg-color="#f56c6c" color="#fff"></mui-button>-->
       <!-- icon-whatsapp -->
	   <!-- @action="makeWhats" -->
		<mui-button  @action="makeReview"  class="gap-row-left" v-if="!showText" icon="icon-message" bg-color="#5cc94f" color="#fff" :text="showText ? 'Review' : ''"></mui-button>
		<mui-button  @action="handleChat"  class="gap-row-left" v-if="showText" icon="icon-message" bg-color="#5cc94f" color="#fff" text="Chat"></mui-button>
   <mui-button  @action="handleReserve"  class="gap-row-left" v-if="showText" icon="icon-back" bg-color="#5cc94f" color="#fff" text="Reserve"></mui-button>
	</view>
</template>

<script>
export default {
    name: 'contact',
    props: ['phone', 'email', 'showText','houseid','message','detail','type','start_time','end_time'],
    data() {
        return {};
    },
    computed: {
        user() {
            return this.$store.state.user;
        }
    },
    methods: {
        makeCall(e) {
            if (!this.user) {
                uni.navigateTo({
                    url: '/pages/login/login'
                });

                return;
            }

            if (this.phone) {
                // #ifdef H5
                window.location.href = `tel:${this.phone}`;
                // #endif

                // #ifdef APP-PLUS || APP
                uni.makePhoneCall({
                    phoneNumber: this.phone
                });
                // #endif
            }
        },
        makeWhats(e) {
            if (!this.user) {
                uni.navigateTo({
                    url: '/pages/login/login'
                });
                return;
            }

            if (this.phone) {
                var phone = this.phone.replace('+', '');
                // #ifdef H5
                window.location.href = `https://api.whatsapp.com/send?text=Hello&phone=${phone}`;
                // #endif

                // #ifdef APP-PLUS || APP
                var text = 'Hello';
                plus.runtime.openURL(`https://api.whatsapp.com/send?text=${text}&phone=${phone}`, function (error) {
                    showAlert('Whatsapp No Installed');
                });
                // #endif
            }
        },
		makeReview(){
			if(this.message==1){
				uni.navigateTo({
					url:"/pages/new/chat?userid="+ this.detail.creatorId+'&receiverid='+this.detail.creatorId+'&name='+this.detail.agency_name
				})
			}else{
				// 评论
				uni.navigateTo({
					url:"/pages/review/review?houseid="+this.houseid
				})
			}
			
		},
		handleChat(){
			uni.navigateTo({
				url:"/pages/new/chat?userid="+ this.detail.creatorId+'&receiverid='+this.detail.creatorId+"&name="+this.detail.agency.name
			})
		},
		handleReserve(){
		uni.navigateTo({
			url:"/pages/index/reserve/reserve?houseid="+this.houseid+'&type='+this.type+'&start_time='+this.start_time+'&end_time='+this.end_time
		})
		}
    }
};
</script>

<style></style>
